<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <!-- <view class="jtop_l" @tap="navigateBack">取消</view> -->
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <view class="jtop_c">新建待办</view>
    </view>

    <view class="tophr"></view>

    <view class="addi">
      <textarea
        auto-height="true"
        style="min-height: 150rpx;"
        maxlength="-1"
        placeholder-style="color:#CCCCCC"
        placeholder="写下你的待办事项"
        :value="content"
        @input="onKeyInput_o"
        class="na_t"
      />
    </view>

    <view class="addb">
      <view class="addbi" @tap="to_addry">
        <text class="addbil">参与人</text>
        <image src="../../static/img/jt.png"></image>
        <text class="addbir" v-if="members.length">{{ members.length }}人</text>
      </view>

      <e-picker-plus
        class="addbi"
        @confirm="confirm2"
        mode="YMDhm"
        endRule="2040-12-31 24:59"
      >
        <text class="addbil">提醒我</text>
        <image src="../../static/img/jt.png" @confirm="confirm2"></image>
        <text class="addbir" @confirm="confirm2">{{ reminderTime }}</text>
      </e-picker-plus>

      <!-- <view class="addbi">
				<text class="addbil">提醒我</text>
				<image src="../../static/img/jt.png"></image>
				<text class="addbir">请选择</text>
			</view> -->
    </view>

    <view class="bt" :style="{ opacity: content ? '1' : '.6' }" @click="jsave">
      保存
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),

  data() {
    return {
      repeat_click: true,
      content: '',
      members: [],
      reminderTime: '',
      kssj: ' 2020-08-29',
    };
  },
  onShow() {
    console.log('cccc', uni.getStorageSync('jqeditry'));

    if (uni.getStorageSync('jqeditry') != '[]') {
      this.members = uni.getStorageSync('jqeditry');
    }
    console.log('cccc', this.members);
    var date = new Date(),
      year = date.getFullYear(),
      month = date.getMonth() + 1,
      day = date.getDate(),
      hour = date.getHours() < 10 ? +date.getHours() : date.getHours(),
      minute = date.getMinutes() < 10 ? +date.getMinutes() : date.getMinutes(),
      second = date.getSeconds() < 10 ? +date.getSeconds() : date.getSeconds();
    month >= 1 && month <= 9 ? (month = '0' + month) : '';
    day >= 0 && day <= 9 ? (day = '0' + day) : '';
    var timer = year + '-' + month + '-' + day + ' ' + '00:00';

    this.kssj = timer;
    console.log('11111', this.kssj);
  },

  methods: {
    onKeyInput_o: function(event) {
      this.content = event.detail.value;
    },
    confirm2(e) {
      console.log(e);
      this.reminderTime = e.result;
    },

    jsave() {
      if (!this.repeat_click) {
        return;
      }
      this.repeat_click = false;

      // if(!this.beginDate){
      // 						this.repeat_click = true;
      //	uni.showToast({
      // 		title: '请输入开始时间',
      // 		icon: 'none'
      // 	})
      // 	return
      // }

      if (!this.content) {
        this.repeat_click = true;
        uni.showToast({
          title: '请输入事项内容',
          icon: 'none',
        });
        return;
      }

      var jd = {
        content: this.content,
      };

      if (this.members) {
        jd.participants = this.members;
      }
      if (this.reminderTime) {
        jd.reminderTime = this.reminderTime;
      }

      request({
        url: `/msg/todo-list`,
        data: jd,

        method: 'POST',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000,
              success: function() {
                setTimeout(function() {
                  uni.removeStorageSync('jqeditry');
                  uni.removeStorageSync('jqeditrytx');

                  uni.navigateBack();
                }, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
      });
    },

    // 跳转
    to_add() {
      uni.navigateTo({
        url: '../main/need_add',
      });
    },

    to_addry() {
      uni.navigateTo({
        url: '../doc/doc_user_share',
      });
    },

    navigateBack() {
      uni.navigateBack();
    },
  },
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}
.addi {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px #dddddd, inset 0px -1px 0px #dddddd;
  margin: 20rpx 0 0;
}
.addi text {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
  margin: 0 0 0 30rpx;
}
.addi input {
  width: auto;
  height: 50rpx;
  display: block;
  float: right;
  margin: 20rpx 30rpx 0 0;
  text-align: right;
  line-height: 50rpx;
  font-size: 34rpx;
  color: #999999;
}
.addb {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 20rpx 0 0;
}
.addbi {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 90rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.addb .addbi:last-child {
  border: none;
}
.addbi .addbil {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
}
.addbi .addbir {
  width: auto;
  height: 90rpx;
  display: block;
  float: right;
  line-height: 90rpx;
  font-size: 32rpx;
  color: #999999;
}
.addbi image {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 33rpx 30rpx 0 30rpx;
}
.addi textarea {
  width: 690rpx;
  height: 150rpx;
  display: block;
  float: left;
  margin: 0rpx 30rpx 20rpx;
  text-align: left;
  line-height: 40rpx;
  font-size: 34rpx;
  color: #999999;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
  opacity: 0.5;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}

.jtop_bs {
  width: 100%;
  height: auto;
  background: #ffffff;
  display: block;
  float: left;
}
.jtop_bs view {
  width: 720rpx;
  height: 90rpx;
  background: #ffffff;
  display: block;
  float: left;
  margin: 0 0 0 30rpx;
  border-bottom: 1px solid #dddddd;
}
.jtop_bs view text {
  width: 80%;
  height: 90rpx;
  line-height: 90rpx;
  background: #ffffff;
  display: block;
  float: left;
  font-size: 34rpx;
  color: #000000;
}
.jtop_bs view image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 21rpx 30rpx 0 0;
}
.jtop_tc {
  display: none;
}

.na_t {
  color: #000000;
  margin: 30rpx !important;
}
textarea {
  color: #000000 !important;
}
.bt {
  width: 690rpx;
  height: 94rpx;
  margin: 30rpx;
  display: block;
  float: left;
  background: #256aff;
  mix-blend-mode: normal;
  border-radius: 8rpx;
  font-size: 36rpx;
  line-height: 94rpx;
  text-align: center;
  color: #ffffff;
  opacity: 1;
}
.bt .active {
  opacity: 1;
}
.bt:active {
  opacity: 1;
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}
</style>
